using UnityEngine;
using System.Collections.Generic;

[CreateAssetMenu(fileName = "DialogueData", menuName = "Dialogue/DialogueData")]
public class DialogueData_SO : ScriptableObject
{
    [SerializeField]
    public List<DialoguePiece> dialoguePieces = new List<DialoguePiece>();

    public Dictionary<string, DialoguePiece> dialoguePieceDict = new Dictionary<string, DialoguePiece>();

#if UNITY_EDITOR
    // 当这个 SO 文件被修改时执行
    private void OnValidate()
    {
        dialoguePieceDict.Clear();
        foreach (var piece in dialoguePieces)
        {
            if (!dialoguePieceDict.ContainsKey(piece.ID))
            {
                dialoguePieceDict.Add(piece.ID, piece);
            }
        }
    }
#else
    private void Awake() {
        dialoguePieceDict.Clear();
        foreach (var piece in dialoguePieces)
        {
            if (!dialoguePieceDict.ContainsKey(piece.ID))
            {
                dialoguePieceDict.Add(piece.ID, piece);
            }
        }
    }
#endif
    /// <summary>
    /// 返回对话中的任务
    /// </summary>
    /// <returns></returns>
    public QuestData_SO GetQuest()
    {
        QuestData_SO q = null;
        foreach (var piece in dialoguePieces)
        {
            if (piece.questData != null)
            {
                q = piece.questData;
                break;
            }
        }
        return q;
    }
}